package com.agricultural.robot.chain;

import com.agricultural.robot.model.SafetyEvent;
import com.agricultural.robot.model.SafetyEventType;

/**
 * 安全处理者接口 - 责任链模式
 */
public abstract class SafetyHandler {
    protected SafetyHandler nextHandler;

    public void setNextHandler(SafetyHandler handler) {
        this.nextHandler = handler;
    }

    public abstract boolean canHandle(SafetyEventType type);

    public abstract void handleEvent(SafetyEvent event);

    public void handleSafetyEvent(SafetyEvent event) {
        if (canHandle(event.getType())) {
            handleEvent(event);
        } else if (nextHandler != null) {
            nextHandler.handleSafetyEvent(event);
        } else {
            System.out.println("没有处理器可以处理该安全事件: " + event.getMessage());
        }
    }
}
